cmake_minimum_required(VERSION 3.16)
project(mod_AUTH_LDAP_IP C)

set(CMAKE_C_STANDARD 99)


# Use the static C library for all build types to a target
# MSVC编译时对指定的target设置'/MT'选项连接static c/c++ library
function (with_mt_if_msvc target)
    if(MSVC)
        add_definitions(-D_WIN32_WINNT=0x0601)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
        message(${CMAKE_CXX_FLAGS})
        # Generator expressions
        if(${CMAKE_BUILD_TYPE} MATCHES "Debug")
            set(_mt "/MTd")
        else()
            set(_mt "/MT")
        endif()
        get_target_property(_options ${target} COMPILE_OPTIONS)
        if(_options)
            # message(STATUS "${target} COMPILE_OPTIONS=${_options}")
            if(${_options} MATCHES "/MD")
                string(REGEX REPLACE "/MD" "/MT" _options "${_options}")
            else()
                set(_options "${_options} ${_mt}")
            endif()
        else()
            set(_options "${_mt}")
        endif()
        get_target_property(_type ${target} TYPE)
        # 判断 ${target}是否为静态库
        if(_type STREQUAL "STATIC_LIBRARY")
            # 静态库将/MT选项加入INTERFACE_COMPILE_OPTIONS
            target_compile_options( ${target} PUBLIC "${_options}")
        else()
            target_compile_options( ${target} PRIVATE "${_options}")
        endif()
        # Cleanup temporary variables.
        unset(_mt)
        unset(_options)
        message(STATUS "target ${target} use static runtime /MT")
    endif(MSVC)
endfunction()

add_subdirectory(host_bind_filter)

include_directories(Apache24/include)
link_directories(Apache24/lib)
add_library(mod_auth_host_bind SHARED mod_host_bind_filter.c mod_host_bind_filter.h)

target_link_libraries(mod_auth_host_bind host_bind_filter libhttpd libapr-1 libaprutil-1)
with_mt_if_msvc(mod_auth_host_bind)